
<div style="POSITION: relative" id="content">
  <h3> 使用easyUI给datagrid添加pagination </h3>
  <div id="article_content" class="article_content">
    <p>这个示例展示我们如何从服务器端加载数据和如何添加pagination 到datagrid.</p>
    <p><img src="documentation/images/1344502913_4526.png" alt=""><br>
    </p>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 创建 DataGrid</h4>
    <p> 从服务器端加载数据, 你应该设置'url'属性, 在你的服务器端你应该返回JSON&#26684;式数据.请看datagrid文档得到更多关于它的数据&#26684;式信息.</p>
    <pre name="code" class="html">&lt;table id=&quot;tt&quot; class=&quot;easyui-datagrid&quot; style=&quot;width:600px;height:250px&quot;  
        url=&quot;datagrid2_getdata.php&quot;  
        title=&quot;Load Data&quot; iconCls=&quot;icon-save&quot;  
        rownumbers=&quot;true&quot; pagination=&quot;true&quot;&gt;  
    &lt;thead&gt;  
        &lt;tr&gt;  
            &lt;th field=&quot;itemid&quot; width=&quot;80&quot;&gt;Item ID&lt;/th&gt;  
            &lt;th field=&quot;productid&quot; width=&quot;80&quot;&gt;Product ID&lt;/th&gt;  
            &lt;th field=&quot;listprice&quot; width=&quot;80&quot; align=&quot;right&quot;&gt;List Price&lt;/th&gt;  
            &lt;th field=&quot;unitcost&quot; width=&quot;80&quot; align=&quot;right&quot;&gt;Unit Cost&lt;/th&gt;  
            &lt;th field=&quot;attr1&quot; width=&quot;150&quot;&gt;Attribute&lt;/th&gt;  
            &lt;th field=&quot;status&quot; width=&quot;60&quot; align=&quot;center&quot;&gt;Stauts&lt;/th&gt;  
        &lt;/tr&gt;  
    &lt;/thead&gt;  
&lt;/table&gt;  </pre>
    <p>我们定义datagrid的datagrid和设置'pagination'属性为true,它将生成一个分页工具栏在datagrid的底部pagination将发送2个参数到服务器: </p>
    <div style="text-align:left">
      <ul style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left">
        <li>page: 页码,起始&#20540; 1.</li>
        <li>rows: 每页显示行</li>
      </ul>
      <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 服务器端代码</h4>
      <pre name="code" class="javascript">$page = isset($_POST['page']) ? intval($_POST['page']) : 1;  
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;  
// ...  
$rs = mysql_query(&quot;select count(*) from item&quot;);  
$row = mysql_fetch_row($rs);  
$result[&quot;total&quot;] = $row[0];  
  
$rs = mysql_query(&quot;select * from item limit $offset,$rows&quot;);  
  
$items = array();  
while($row = mysql_fetch_object($rs)){  
    array_push($items, $row);  
}  
$result[&quot;rows&quot;] = $items;  
  
echo json_encode($result);  </pre>
      <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 下载EasyUI示例代码:</h4>
      <div style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left; padding-left:50px"> <a href="http://www.jeasyui.com/tutorial/datagrid/downloads/easyui-datagrid2-demo.zip" target="_blank" class="download-link" style="color:rgb(0,0,255)">easyui-datagrid-demo.zip</a></div>
      <br>
      <br>
    </div>
  </div>
</div>
<SCRIPT type=text/javascript>
	dp.SyntaxHighlighter.ClipboardSwf = 'documentation/js/clipboard.swf'/*tpa=http://jeasyui.com/SyntaxHighlighter/Scripts/clipboard.swf*/;
	dp.SyntaxHighlighter.HighlightAll('code');
</SCRIPT>